﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Yugi_Gui.Animation
{
    public class AnimationSchedue
    {
        List<ISchedue> works = new List<ISchedue>();
        Action final;
        int index = 0;
        Action complete;

        public AnimationSchedue(Action final, params ISchedue[] objs)
        {
            this.final = final;
            works.AddRange(objs);
            complete = new Action(this.Complete);
        }
        public void SetFinal(Action final)
        {
            this.final = final;
        }
        public void Start()
        {
            index = 0;
            works[index++].DoWork(complete);
        }

        private void Complete()
        {
            if (index < works.Count)
            {
                works[index++].DoWork(complete);
            }
            else
            {
                final();
            }
        }
    }
}
